﻿using System.Linq;
using UniMana.Utils.Controls;
using System;

namespace UniMana.Data
{
    public class Catalogue_Course_SchoolYear_TermInfo
    {
        #region /*Không thay đổi*/
        public bds m_bds = new bds();
        public void Save()
        {
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
        }
        #endregion /*Không thay đổi*/
        private DBMain m_data = new DBMain();
        #region [Properties - Thuộc tính]
        public Catalogue_Course_SchoolYear_Term Properties
        {
            get { return m_bds.Current as Catalogue_Course_SchoolYear_Term; }
        }
        #endregion
        public Catalogue_Course_SchoolYear_TermInfo(int CourseKey=0,int SchoolYearKey=0,int TermKey =0)
        {
            var IQuery = m_data.m_DCSave.Catalogue_Course_SchoolYear_Terms.Where(
                        tb => tb.Catalogue_TermKey == TermKey &&
                        tb.Catalogue_SchoolYearKey == SchoolYearKey &&
                        tb.Catalogue_CourseKey == CourseKey);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Catalogue_Course_SchoolYear_Term();
                m_bds.Add(Row);
            }
        }
        #region [An]
        public Catalogue_Course_SchoolYear_TermInfo(int m_iCatalogue_CourseKey = 0)
        {
            var IQuery = m_data.m_DCSave.Catalogue_Course_SchoolYear_Terms.Where(tb => tb.Catalogue_CourseKey == m_iCatalogue_CourseKey && tb.DateBegin > SysDateTime.Now);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Catalogue_Course_SchoolYear_Term();
                m_bds.Add(Row);
            }
        }
        #endregion
    }
}